""""""
"""
对于list、set和dict来说, 直接赋值, 其实就是把内存地址交给变量, 并不是复制一份内容
"""
lst1 = ["aaa", "bbb"]
lst2 = lst1
print(id(lst1), id(lst2)) #4739656 4739656
print(lst1, lst2) #['aaa', 'bbb'] ['aaa', 'bbb']
lst1.append("ccc")
print(lst1, lst2) #['aaa', 'bbb', 'ccc'] ['aaa', 'bbb', 'ccc']


"""浅拷贝
内存地址和内容也不一样, 实现了内存的拷贝
"""
#例1
lst1 = ["aaa", "bbb"]
lst2 = lst1.copy()
print(id(lst1), id(lst2)) #4871240 31129672
print(lst1, lst2) #['aaa', 'bbb'] ['aaa', 'bbb']
lst1.append("ccc")
print(lst1, lst2) #['aaa', 'bbb', 'ccc'] ['aaa', 'bbb']
#例2, 只会拷贝第一层, 第二层不会拷贝, 所以称为浅拷贝
lst1 = ["aaa", "bbb", ["1", "2"]]
lst2 = lst1.copy()
print(id(lst1), id(lst2)) #34581256 4805704
print(lst1, lst2) #['aaa', 'bbb', ['1', '2']] ['aaa', 'bbb', ['1', '2']]
lst1[2].append("3")
print(lst1, lst2) #['aaa', 'bbb', ['1', '2', '3']] ['aaa', 'bbb', ['1', '2', '3']]


"""深拷贝
"""
import copy
lst1 = ["aaa", "bbb", ["1", "2"]]
lst2 = copy.deepcopy(lst1)
lst1[2].append("3")
print(id(lst1[2]), id(lst2[2])) #4192392 33359816
print(lst1, lst2) # ['aaa', 'bbb', ['1', '2', '3']] ['aaa', 'bbb', ['1', '2']]





